package itsos.controller;

import itsos.service.IssueBoxService;
import itsos.service.RepositoryService;

import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class IntroController extends MultiActionController {
	
	private RepositoryService repositoryService;
	private IssueBoxService issueBoxService;
	

	
	public void setIssueBoxService(IssueBoxService issueBoxService) {
		this.issueBoxService = issueBoxService;
	}

	
	public void setRepositoryService(RepositoryService repositoryService)
	{
		this.repositoryService = repositoryService;
	}
	
	public ModelAndView doIntro(HttpServletRequest request, HttpServletResponse response)
	{
		ModelAndView mav = new ModelAndView("workpage/mainissue/introPage");
		
		if(request.getSession().getAttribute("memberID")!=null)
		mav.addObject("issueBox", issueBoxService.getIssueBox(request));
		mav.addObject("treeView", repositoryService.getRepository());
		
		return mav;
	}


	protected ModelAndView handleNoSuchRequestHandlingMethod(NoSuchRequestHandlingMethodException noSuchRequestHandlingMethodException, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
		return doIntro(httpServletRequest, httpServletResponse);
	}
	
	
	public ModelAndView doMain(HttpServletRequest request, HttpServletResponse response)
	{
		ModelAndView mav = new ModelAndView("workpage/mainissue/introPage");
		
		if(request.getSession().getAttribute("memberID")!=null)
		mav.addObject("issueBox", issueBoxService.getIssueBox(request));
		mav.addObject("treeView", repositoryService.getRepository());
		return mav;
	}
	
	
	
}
